package com.graduation.springbootinit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.graduation.springbootinit.model.entity.CulturePart.CulturePartComment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CulturePartCommentMapper extends BaseMapper<CulturePartComment> {
    
    /**
     * 获取讨论的一级评论列表（分页）
     */
    @Select("SELECT * FROM culture_part_comments WHERE discussion_id = #{discussionId} AND parent_id IS NULL AND status = 0 AND is_deleted = 0 ORDER BY create_time DESC")
    Page<CulturePartComment> selectPageByDiscussionId(Page<CulturePartComment> page, @Param("discussionId") Long discussionId);
    
    /**
     * 获取评论的回复列表
     */
    @Select("SELECT * FROM culture_part_comments WHERE parent_id = #{parentId} AND status = 0 AND is_deleted = 0 ORDER BY create_time ASC")
    List<CulturePartComment> selectRepliesByParentId(@Param("parentId") Long parentId);
    
    /**
     * 增加点赞数
     */
    @Select("UPDATE culture_part_comments SET like_count = like_count + 1 WHERE id = #{id}")
    void incrementLikeCount(@Param("id") Long id);
    
    /**
     * 增加回复数
     */
    @Select("UPDATE culture_part_comments SET reply_count = reply_count + 1 WHERE id = #{id}")
    void incrementReplyCount(@Param("id") Long id);
    
    /**
     * 获取用户的评论列表
     */
    @Select("SELECT * FROM culture_part_comments WHERE user_id = #{userId} AND status = 0 AND is_deleted = 0 ORDER BY create_time DESC")
    Page<CulturePartComment> selectByUserId(Page<CulturePartComment> page, @Param("userId") Long userId);
}